#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>

/*
Reveal cards from your deck until you reveal 2 Treasure cards. 
Put those Treasure cards in your hand and discard the other revealed cards.
*/

int main(int argc, char const *argv[]){

	int i, n, r, p, deckCount, discardCount, handCount, randCard, copperCountBefore, copperCountAfter;

  	int k[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall};

	struct gameState G;
	
	int * bonus;
	
	int choice1, choice2, choice3, handPos;
	choice1 = 0;
	choice2 = 0;
	choice3 = 0;
	handPos = 0;
	
  	SelectStream(2);
  	PutSeed(3);

	for(int m = 0; m < 10000; m++){
		if ( m % 70 == 0){
			r = initializeGame(2, k, 1, &G);
		}	    
		p = floor(Random() * 2);
	    G.deckCount[p] = floor(Random() * MAX_DECK);
	    G.discardCount[p] = floor(Random() * MAX_DECK);
	    G.handCount[p] = floor(Random() * MAX_HAND);

		// generate a hand
		for (i = 0; i < G.handCount[p]; i++){
			randCard = floor(Random() * treasure_map);
			
			if (m > 100 && m < 200){
				if (randCard == 4){
					randCard == 0;
				}
			}
			
			// count the copper before
			if (randCard == copper){
				copperCountBefore++;
			}
			
			G.hand[p][i] = randCard;	
		}

		//G.whoseTurn = p;
		r = cardEffect(cutpurse, choice1, choice2, choice3, &G, handPos, bonus);
		
		// count copper after
		for (i = 0; i < G.handCount[p]; i++){
			if (G.hand[p][i] == copper){
				copperCountAfter++;
			}
		}
		
		char * fail; 
		
		if(copperCountBefore > 0){
			if(copperCountBefore - copperCountAfter != 1){
				fail = "FAIL\0";
			}else{
				fail = "    \0";
			}
		}
		printf("Copper count before: %2d \t after:%2d \t%s\n", copperCountBefore, copperCountAfter, fail);
		assert(r == 0);
		copperCountBefore = 0;
		copperCountAfter = 0;
	}
	
	
	printf("All tests passed\n");

	return 0;
}